﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using B10.Models;
using System.Web.Security;

namespace B10.Controllers
{
    public class SetupDataBaseController : Controller
    {

        IDatabaseRepository _db;

        public SetupDataBaseController(IDatabaseRepository db)
        {
            this._db = db;
        }

        public SetupDataBaseController() : this(new DatabaseRepository())
        { }

      //  [Authorize(Roles="Admin")]
        public ActionResult Index()
        {
            
            if (Roles.GetAllRoles().Length == 0)
            {
                Roles.CreateRole("Admin");
                //Roles.CreateRole("Accepted");
            }
            

            MembershipUserCollection coll =  Membership.FindUsersByName(User.Identity.Name);
            MembershipUser user = null;
            if  (coll.Count > 0 )
            {
                user = coll[User.Identity.Name];
                Roles.AddUserToRole(user.UserName, "Admin");               
            }
            return View();
        }

    }
}
